﻿using Engine.FileFormats3D.WR2TerrainLoader.QadFile;
using System;
using System.Drawing;
using System.Windows.Forms;

namespace Engine.WindowsFormsControls
{
    public partial class UCWR2Light : UserControl
    {
        #region Private Fields

        private Light light;

        #endregion Private Fields

        #region Public Constructors

        public UCWR2Light()
        {
            InitializeComponent();
            this.light = new Light();
            UpdateValues();
        }

        #endregion Public Constructors

        #region Internal Properties

        internal Light Wr2Light
        {
            get
            {
                return light;
            }
            set
            {
                SetControls(value);
            }
        }

        #endregion Internal Properties

        #region Private Methods

        private void Control_ValueChanged(object sender, EventArgs e)
        {
            UpdateValues();
        }

        private void SetControls(Light wr2Light)
        {
            this.numericUpDown_PositionX.Value = (decimal)wr2Light.PositionX;
            this.numericUpDown_PositionY.Value = (decimal)wr2Light.PositionY;
            this.numericUpDown_PositionZ.Value = (decimal)wr2Light.PositionZ;
            this.panel_LightColor.BackColor = Color.FromArgb(wr2Light.Color);
            this.numericUpDown_BlinkOffset.Value = (decimal)wr2Light.BlinkOffset;
            this.numericUpDown_BlinkDuration.Value = (decimal)wr2Light.BlinkDuaration;
            this.numericUpDown_BlinkSize.Value = (decimal)wr2Light.BlinkSize;
            this.numericUpDown_RotateY.Value = (decimal)wr2Light.OrientationY;
        }

        private void UpdateValues()
        {
            this.light.PositionX = (float)this.numericUpDown_PositionX.Value;
            this.light.PositionY = (float)this.numericUpDown_PositionY.Value;
            this.light.PositionZ = (float)this.numericUpDown_PositionZ.Value;
            this.light.Color = this.panel_LightColor.BackColor.ToArgb();
            this.light.BlinkOffset = (float)this.numericUpDown_BlinkOffset.Value;
            this.light.BlinkDuaration = (float)this.numericUpDown_BlinkDuration.Value;
            this.light.BlinkSize = (float)this.numericUpDown_BlinkSize.Value;
            this.light.OrientationY = (float)this.numericUpDown_RotateY.Value;
        }

        #endregion Private Methods
    }
}